import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:mziot/app/config/design.dart';
import 'package:mziot/generated/locales.g.dart';

import '../controllers/password_controller.dart';

class PasswordView extends GetView<PasswordController> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(LocaleKeys.password_title.tr),
        centerTitle: true,
      ),
      body: Container(
        padding: EdgeInsets.symmetric(horizontal: 24),
        child: Column(
          children: [
            SizedBox(height: 32),
            _textField(LocaleKeys.public_e_mail.tr, controller.passwordController),
            SizedBox(height: 32),
            _textField(LocaleKeys.public_verification_code.tr, controller.repeatController),
            SizedBox(height: 158),
            _nextButton,
          ],
        ),
      ),
    );
  }

  Widget _textField(String hintText, TextEditingController editingController) {
    return TextField(
      controller: editingController,
      obscureText: true,
      decoration: InputDecoration(
        contentPadding: EdgeInsets.only(bottom: 8),
        hintText: hintText,
        isDense: true,
        hintStyle: MFont.regular13.apply(color: MColor.xFF333333_60),
        labelStyle: MFont.semi_Bold15.apply(color: MColor.xFF333333),
        enabledBorder: UnderlineInputBorder(
          borderSide: BorderSide(color: MColor.xFFCCCCCC, width: 0.5),
        ),
        focusedBorder: UnderlineInputBorder(
          borderSide: BorderSide(color: MColor.xFF000000, width: 1),
        ),
      ),
      textAlignVertical: TextAlignVertical.bottom,
      onChanged: (text) {
        if (editingController == controller.passwordController) {
          controller.password.value = text;
        } else {
          controller.repeatPassword.value = text;
        }
      },
    );
  }

  get _nextButton {
    return Container(
      width: double.infinity,
      height: 44,
      child: Obx(() {
        return TextButton(
          style: ButtonStyle(
              backgroundColor: MaterialStateProperty.all(
                  controller.buttonEnable.value ? MColor.xFF000000 : MColor.xFFEEEEEE),
              shape: MaterialStateProperty.all(StadiumBorder())),
          onPressed: () {},
          child: Text(
            LocaleKeys.public_ok.tr,
            style: MFont.semi_Bold17
                .apply(color: controller.buttonEnable.value ? Colors.white : MColor.xFF999999),
          ),
        );
      }),
    );
  }
}
